package com.wind.taobao.api.jianghu.convert
{
	import com.wind.taobao.api.jianghu.model.SpacePicture;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * SpacePicture 转换器
	 * @author fxy
	 *
	 */
	public class SpacePictureConvert
	{
		/**
		 * 转换SpacePicture集合
		 */
		public static function convertSpacePictures(value:Object, type:String="json"):ArrayCollection
		{
			var spacePictures:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							spacePictures.addItem(convertSpacePicture((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return spacePictures;
		}

		/**
		 * 转换SpacePicture
		 */
		public static function convertSpacePicture(value:Object, type:String="json"):SpacePicture
		{
			var spacePicture:SpacePicture=new SpacePicture();
			if (value == null)
				return spacePicture;
			if (type == TaobaoConstants.XML)
			{
				spacePicture=convertXMLToSpacePicture(XML(value), spacePicture);
			}
			else
			{
				spacePicture=convertJSONToSpacePicture(value, spacePicture);
			}
			return spacePicture;
		}

		/**
		 * JSON转换为SpacePicture
		 */
		private static function convertJSONToSpacePicture(json:Object, spacePicture:SpacePicture):SpacePicture
		{
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_ID))
			{
				spacePicture.picture_id=json[TaobaoConstants.PICTURE_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.NAME))
			{
				spacePicture.name=json[TaobaoConstants.NAME];
			}
			if (json.hasOwnProperty(TaobaoConstants.ALBUMID))
			{
				spacePicture.ablumId=json[TaobaoConstants.ALBUMID];
			}
			if (json.hasOwnProperty(TaobaoConstants.FILE_PATH))
			{
				spacePicture.file_path=json[TaobaoConstants.FILE_PATH];
			}
			if (json.hasOwnProperty(TaobaoConstants.FILE_SIZE))
			{
				spacePicture.file_size=json[TaobaoConstants.FILE_SIZE];
			}
			return spacePicture;
		}

		/**
		 * XML转换为SpacePicture
		 */
		private static function convertXMLToSpacePicture(value:XML, spacePicture:SpacePicture):SpacePicture
		{
			return spacePicture;
		}

	}
}